/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.material.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springblade.modules.material.entity.PaperReleaseDetailEntity;
import org.springblade.modules.material.entity.PaperReleaseEntity;
import org.springblade.modules.material.vo.PaperReleaseDetailVO;
import org.springblade.modules.material.excel.PaperReleaseDetailExcel;
import org.springblade.modules.material.mapper.PaperReleaseDetailMapper;
import org.springblade.modules.material.service.IPaperReleaseDetailService;
import org.springblade.modules.material.vo.PaperReleaseVO;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl;
import java.util.List;

/**
 * 考试发布后的试卷详情表 服务实现类
 *
 * @author junxin
 * @since 2023-04-27
 */
@Service
public class PaperReleaseDetailServiceImpl extends BaseServiceImpl<PaperReleaseDetailMapper, PaperReleaseDetailEntity> implements IPaperReleaseDetailService {

	@Override
	public IPage<PaperReleaseDetailVO> selectPaperReleaseDetailPage(IPage<PaperReleaseDetailVO> page, PaperReleaseDetailVO paperReleaseDetail) {
		return page.setRecords(baseMapper.selectPaperReleaseDetailPage(page, paperReleaseDetail));
	}


	@Override
	public List<PaperReleaseDetailExcel> exportPaperReleaseDetail(Wrapper<PaperReleaseDetailEntity> queryWrapper) {
		List<PaperReleaseDetailExcel> paperReleaseDetailList = baseMapper.exportPaperReleaseDetail(queryWrapper);
		//paperReleaseDetailList.forEach(paperReleaseDetail -> {
		//	paperReleaseDetail.setTypeName(DictCache.getValue(DictEnum.YES_NO, PaperReleaseDetail.getType()));
		//});
		return paperReleaseDetailList;
	}

	@Override
	public List<PaperReleaseDetailEntity> queryByReleaseId(String releaseId) {
		return baseMapper.selectList(Wrappers.<PaperReleaseDetailEntity>query().lambda().eq(PaperReleaseDetailEntity::getReleaseId,releaseId));
	}


	public static void setQuestionScore(int questionType, PaperReleaseEntity source, PaperReleaseDetailEntity paperReleaseDetailEntity ){
		switch (questionType){
			case 1:
				paperReleaseDetailEntity.setValue(source.getSingleScore());
				break;
			case 2:
				paperReleaseDetailEntity.setValue(source.getMultipleScore());
				break;
			case 3:
				paperReleaseDetailEntity.setValue(source.getJudgeScore());
				break;
			case 4:
				paperReleaseDetailEntity.setValue(source.getFillScore());
				break;
			case 5:
				paperReleaseDetailEntity.setValue(source.getShortScore());
				break;

		}
	}
}
